package com.example.controller;

import com.example.domain.ResponseResult;
import com.example.domain.dto.ModAuthorityDto;
import com.example.service.AuthorityService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/authority")
public class AuthorityController {
    @Resource
    private AuthorityService authorityService;
    @PostMapping("/list")
    @PreAuthorize("@ps.hasPermission('authorityList')")
    public ResponseResult getAuthorityList(){
        return authorityService.getAuthorityList();
    }

    @PostMapping("/delete")
    @PreAuthorize("@ps.hasPermission('authorityDelete')")
    public ResponseResult deleteAuthority(@RequestBody Map<String,Integer> map){
        return authorityService.deleteAuthority(map);
    }

    @PostMapping("/modInit")
    @PreAuthorize("@ps.hasPermission('authorityEdit')")
    public ResponseResult modInitAuthority(@RequestBody Map<String,Integer> map){
        return authorityService.modInitAuthority(map);
    }

    @PostMapping("/mod")
    @PreAuthorize("@ps.hasPermission('authorityEdit')")
    public ResponseResult modAuthority(@RequestBody ModAuthorityDto modAuthorityDto){
        return authorityService.modAuthority(modAuthorityDto);
    }

    @PostMapping("/addInit")
    @PreAuthorize("@ps.hasPermission('authorityAdd')")
    public ResponseResult addInitAuthority(){
        return authorityService.addInitAuthority();
    }
    @PostMapping("/add")
    @PreAuthorize("@ps.hasPermission('authorityAdd')")
    public ResponseResult addAuthority(@RequestBody ModAuthorityDto modAuthorityDto ){
        return authorityService.addAuthority(modAuthorityDto);
    }

}
